package com.qfhd.soft.cjzcore.Model;

import com.qfhd.soft.cjzcore.Core.CJJsonUtils;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

public class Task_try_detail_section_model implements Comparable<Task_try_detail_section_model> {
//     "section_id": 1,
//             "days": 1,
//             "operate_time": 300,
//             "section_reward": 30,
//             "task_id": 1,
//             "state": 0
    public int section_id;
    public int days;//第几天
    public int operate_time;//试玩时长
    public int section_reward;
    public int task_id;
    public int state;//0:未完成 其他：完成

    @Override
    public int compareTo(Task_try_detail_section_model o) {
        int i = this.days - o.days;//先按照年龄排序
//        if(i == 0){
//            return this.score - o.getScore();//如果年龄相等了再用分数进行排序
//        }
        return i;
    }

    public static Task_try_detail_section_model getModelByJSONObject(JSONObject object){
        Task_try_detail_section_model model = new Task_try_detail_section_model();
        model.days = CJJsonUtils.getValueFromKey_int(object,"days");
        model.operate_time = CJJsonUtils.getValueFromKey_int(object,"operate_time");
        model.section_id = CJJsonUtils.getValueFromKey_int(object,"section_id");
        model.section_reward = CJJsonUtils.getValueFromKey_int(object,"section_reward");
        model.state = CJJsonUtils.getValueFromKey_int(object,"state");
        model.task_id = CJJsonUtils.getValueFromKey_int(object,"task_id");
        return model;
    }

    public static List<Task_try_detail_section_model> getListByJSONObject(JSONArray array){
        List<Task_try_detail_section_model> list = new ArrayList<>();
        for(int i=0; i<array.length(); i++){
            try {
                JSONObject tmp = array.getJSONObject(i);
                list.add(getModelByJSONObject(tmp));
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return list;
    }
}
